﻿// Copyright (C) 2012-2013 Weekend Game Studio
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to
// deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.

#region Using Statements
using System;
using WaveEngine.Common.Input;
using WaveEngine.Framework;
using WaveEngine.Framework.Services;
#endregion

namespace PhysicWallProject
{
    public class MySceneBehavior : SceneBehavior
    {
        private bool diagnostics;
        private Input inputService;
        private KeyboardState beforeKeyboardState;

        /// <summary>
        /// Initializes a new instance of the <see cref="MySceneBehavior" /> class.
        /// </summary>
        public MySceneBehavior()
            : base("MySceneBehavior")
        {
            this.diagnostics = true;           
        }

        /// <summary>
        /// Resolves the dependencies needed for this instance to work.
        /// </summary>
        protected override void ResolveDependencies()
        {
            WaveServices.ScreenLayers.SetDiagnosticsActive(this.diagnostics);
            this.Scene.RenderManager.DebugLines = this.diagnostics;
        }

        /// <summary>
        /// Allows this instance to execute custom logic during its <c>Update</c>.
        /// </summary>
        /// <param name="gameTime">The game time.</param>
        /// <remarks>
        /// This method will not be executed if it are not <c>Active</c>.
        /// </remarks>
        protected override void Update(TimeSpan gameTime)
        {
             inputService = WaveServices.Input;

             if (inputService.KeyboardState.IsConnected)
             {
                 // Key F1
                 if (inputService.KeyboardState.F1 == ButtonState.Pressed &&
                     beforeKeyboardState.F1 != ButtonState.Pressed)
                 {
                     this.diagnostics = !this.diagnostics;
                     WaveServices.ScreenLayers.SetDiagnosticsActive(this.diagnostics);
                     this.Scene.RenderManager.DebugLines = this.diagnostics;
                 }
             }

             this.beforeKeyboardState = inputService.KeyboardState;
        }
    }
}
